<?php
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
	#CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id

	+ Module  		: t_rapk View
	+ Description	: For record view
	+ Filename 		: v_t_rapk.php
 	+ creator  		: 
 	+ Created on 24/Jul/2012 10:52:52

*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
		
		table.imagetable {
			font-family: verdana,arial,sans-serif;
			font-size:11px;
			color:#333333;
			border-width: 1px;
			border-color: #999999;
			border-collapse: collapse;
		}
		table.imagetable th {
			background-color:#b5cfd2;
			border-width: 1px;
			padding: 8px;
			border-style: solid;
			border-color: #999999;
		}
		table.imagetable td {
			background-color:#dcddc0;
			border-width: 1px;
			padding: 8px;
			border-style: solid;
			border-color: #999999;
		}
    </style>
<script>
/* declare function */
var t_rapk_DataStore;
var var_job_id;
var t_rapk_ColumnModel;
var t_rapk_ListEditorGrid;
var t_rapk_saveForm;
var t_rapk_SelectedRow;
var total_rapk;
/* decalare KONSTANSTA */
var FAILED_SAVE="Data gagal disimpan";
var FAILED_CONNECTION="Koneksi database server gagal, hubungi Administrator";
var FAILED_VALID_FORM="Data input belum sempurna";
var FAILED_DELETE_SELECTED="Tidak ada data yang terpilih untuk dihapus";
var FAILED_UPDATE_SELECTED="Tidak ada data yang terpilih untuk diupdate";
var FAILED_DELETE="Data gagal dihapus";
var FAILED_EXCEL="Data gagal diexport ke Excel";
var FAILED_PRINT="Data gagal dicetak";
var FAILED_PERMISSION="Anda tidak mempunyai akses untuk aksi ini";
var CONFIRM_DELETE="Apakah Anda yakin menghapus rekod ini?";
var CONFIRM_MULTI_DELETE="Apakah Anda yakin menghapus rekod-rekod ini?";
var SUCCESS_SAVE="Data sukses disimpan";
var TITLE_LIST="Daftar Data";
var TITLE_FORM="Form Input/Update";
var TITLE_FORM_SEARCH="Pencarian Lanjut";
var BTN_SAVE="Simpan";
var BTN_SEARCH="Cari";
var BTN_CANCEL="Batal";
var BTN_ADD_TITLE="Tambah";
var BTN_EDIT_TITLE="Ubah";
var BTN_DELETE_TITLE="Hapus";
var BTN_SEARCH_TITLE="Pencarian";
var BTN_PRINT_TITLE="Cetak";
var BTN_EXCEL_TITLE="Export Excel";
var BTN_REFRESH_TITLE="Refresh";
var BTN_ADD_TOOLTIP="Tambah Data Baru";
var BTN_EDIT_TOOLTIP="Ubah Data";
var BTN_DELETE_TOOLTIP="Hapus Data";
var BTN_SEARCH_TOOLTIP="Pencarian Data Lanjut";
var BTN_SIMPLE_SEARCH_TOOLTIP="Pencarian Sederhana";
var BTN_PRINT_TOOLTIP="Cetak Data (html)";
var BTN_EXCEL_TOOLTIP="Export ke bentuk Excel";
var BTN_REFERSH_TOOLTIP="Refresh Data";
var INFO_REQUIRED="Wajib diisi";
var PERMISSION="RCUD";
//declare konstant
var post2db = 'CREATE';
var msg = 'created';
var pageS=15;

var array_jobdet_id = [];

/* on ready fuction */
Ext.onReady(function(){
  	Ext.QuickTips.init();	/* Initiate quick tips icon */
  	
  	Ext.util.Format.comboRenderer = function(combo){
  	    return function(value){
  	        var record = combo.findRecord(combo.valueField, value);
  	        return record ? record.get(combo.displayField) : combo.valueNotFoundText;
  	    };
  	};
  	
  	/* START DATA */
  	t_rapk_DataStore = new Ext.data.Store({
		id: 't_rapk_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_rapk&m=get_action',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'rapk_id'
		},[
			{name: 'rapk_id', type: 'int', mapping: 'rapk_id'},
			{name: 'branch_id', type: 'int', mapping: 'branch_id'},
			{name: 'branch_name', type: 'string', mapping: 'branch_name'},
			{name: 'project_id', type: 'int', mapping: 'project_id'},
			{name: 'project_name', type: 'string', mapping: 'project_name'},
			{name: 'project_code', type: 'string', mapping: 'project_code'},
			{name: 'job_id', type: 'int', mapping: 'job_id'},
			{name: 'job_name', type: 'string', mapping: 'job_name'},
			{name: 'm_div_id', type: 'int', mapping: 'm_div_id'},
			{name: 'div_id', type: 'int', mapping: 'div_id'},
			{name: 'div_name', type: 'string', mapping: 'div_name'},
			{name: 'rapk_procurement', type: 'string', mapping: 'rapk_procurement'}
		]),
		sortInfo:{field: 'project_code', direction: "ASC"}
	});
  	t_rapk_DataStore.load({params: {start: 0, limit: pageS}});	// load DataStore
  	
	var branchDataStore = new Ext.data.Store({
		id: 'branchDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_branch', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'branch_id'
		},[
			{name: 'branch_id', type: 'int', mapping: 'branch_id'},
			{name: 'branch_name', type: 'string', mapping: 'branch_name'},
			{name: 'branch_active', type: 'string', mapping: 'branch_active'},
			{name: 'dvo_id', type: 'int', mapping: 'dvo_id'},
			{name: 'dvo_name', type: 'string', mapping: 'dvo_name'}
		]),
		sortInfo:{field: 'branch_name', direction: "ASC"}
	});
	
	var project_codeDataStore = new Ext.data.Store({
		id: 'project_codeDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_project', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'project_id'
		},[
			{name: 'project_id', type: 'int', mapping: 'project_id'},
			{name: 'project_name', type: 'string', mapping: 'project_name'},
			{name: 'project_code', type: 'string', mapping: 'project_code'},
			{name: 'div_id', type: 'int', mapping: 'm_div_id'}
		]),
		sortInfo:{field: 'project_code', direction: "ASC"}
	});
	var tpl_projectDS = new Ext.XTemplate(
			'<tpl for="."><div class="search-item">',
            '<span><b>[{project_code}]</b><br /></span>',
            '{project_name}',
            '</div></tpl>'
	);
	
	var jobDataStore = new Ext.data.Store({
		id: 'jobDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_job', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'job_id'
		},[
			{name: 'job_id', type: 'int', mapping: 'job_id'},
			{name: 'job_name', type: 'string', mapping: 'job_name'},
			{name: 'm_div_id', type: 'int', mapping: 'm_div_id'}
		]),
		sortInfo:{field: 'job_name', direction: "ASC"}
	});
	
	var m_jobdet_reader=new Ext.data.JsonReader({
		root: 'results',
		totalProperty: 'total',
		id: 'jobdet_id'
	},[
	/* dataIndex => insert intoperawatan_ColumnModel, Mapping => for initiate table column */
			{name: 'id', type: 'int', mapping: 'id'}, 
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'}, 
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'rapkdet_volume', type: 'float', mapping: 'rapkdet_volume'},
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'},
			{name: 'rapkdet_price', type: 'float', mapping: 'rapkdet_price'},
			{name: 'rapkdet_publish', type: 'int', mapping: 'rapkdet_publish'},
			{name: 'rapkdet_id', type: 'int', mapping: 'rapkdet_id'}
	]);
	
	var jobdetDataStore = new Ext.data.Store({
		id: 'jobdetDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_rapk&m=rapkdet_list', 
			method: 'POST'
		}),
		reader: m_jobdet_reader,
		sortInfo:{field: 'jobdet_id', direction: "ASC"}
	});
	
	var jobdet_allDataStore = new Ext.data.Store({
		id: 'jobdet_allDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_jobdet_all', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15, task: 'all'},
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'jobdet_id'
		},[
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'},
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'job_id', type: 'int', mapping: 'job_id'},
			{name: 'job_name', type: 'string', mapping: 'job_name'}
		]),
		sortInfo:{field: 'jobdet_name', direction: "ASC"}
	});
	var tpl_jobdetDS = new Ext.XTemplate(
			'<tpl for="."><div class="search-item">',
            '<span><b>[{jobdet_name}]</b><br /></span>',
            'Material: {job_name}',
            '</div></tpl>'
	);

	var unitDataStore = new Ext.data.Store({
		id: 'unitDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_unit', 
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'unit_id'
		},[
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'}
		]),
		sortInfo:{field: 'unit_name', direction: "ASC"}
	});
	
	var divDataStore = new Ext.data.Store({
		id: 'divDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_div', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'div_id'
		},[
			{name: 'div_id', type: 'int', mapping: 'div_id'},
			{name: 'div_name', type: 'string', mapping: 'div_name'}
		]),
		sortInfo:{field: 'div_name', direction: "ASC"}
	});
  	/* END DATA */
  	
  	
  	/* START FORM */
	//detail
	var rapk_jobdet_total_cfField= new Ext.form.TextField({
		id: 'rapk_jobdet_total_cfField',
		fieldLabel: '<span style="font-weight:bold">Total RAPK (Rp)</span>',
		allowNegatife : false,
		enableKeyEvents: true,
		itemCls: 'rmoney',
		width: 160,
		readOnly: true,
		maskRe: /([0-9]+)$/ 
	});
	
	var rapk_jobdet_totalGroup = new Ext.form.FieldSet({
		title: '-',
		labelWidth: 140,
		autoHeight: true,
		collapsible: false,
		layout:'form',
		frame: false,
		items:[rapk_jobdet_total_cfField]
	});

	var rapk_jobdet_name_field_temp = new Ext.form.NumberField();
	var rapk_jobdet_name_selected = new Ext.form.NumberField({
		value: 0
	});
	var rapk_jobdet_nameField=new Ext.form.ComboBox({
		store: jobdet_allDataStore,
		mode: 'remote',
		displayField: 'jobdet_name',
		valueField: 'jobdet_id',
		loadingText: 'Searching...',
		typeAhead: false,
		pageSize: pageS,
		triggerAction: 'all',
		lazyRender:false,
		tpl: tpl_jobdetDS,
		itemSelector: 'div.search-item',
		listClass: 'x-combo-list-small',
		anchor: '80%',
		hideTrigger: false,
		forceSelection:true
	});
	rapk_jobdet_nameField.on("select",function(){
		rapk_jobdet_name_selected.setValue(1);
		var j=jobdet_allDataStore.findExact('jobdet_id',rapk_jobdet_nameField.getValue());
		if(j>-1){
			var data_jobdet = jobdet_allDataStore.getAt(j);
			rapk_jobdet_name_field_temp.setValue(data_jobdet.data.jobdet_id);
		}
		
	});
	//column model jobdet
	var rapkdet_unitField = new Ext.form.ComboBox({
		id: 'rapkdet_unitField',
		store: unitDataStore,
		mode: 'remote',
		displayField:'unit_name',
		valueField: 'unit_id',
        editable: false,
        forceSelection: true,
		triggerAction: 'all'
	});
	var rapkdet_publishColumn = new Ext.grid.CheckColumn({
		header: "Publish", 
		dataIndex: 'rapkdet_publish', 
		width: 80,
		hidden: false,
		sortable: false
	});
	var rapkdetColumnModel = new Ext.grid.ColumnModel(
		[{
			header: 'rapkdet_id',
			dataIndex: 'rapkdet_id',
			hidden: true
		},
		{
			header: 'Jenis, Merk, dan Ukuran Material',
			id: 'jobdet_jenis_merk_ukuran',
			dataIndex: 'jobdet_id',
			editor: rapk_jobdet_nameField,
			renderer: Ext.util.Format.comboRenderer(rapk_jobdet_nameField)
		},
		{
			header: '<div style="text-align: center">Vol</div>',
			dataIndex: 'rapkdet_volume',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				allowNegative: false,
				blankText: '0',
				maxLength: 10,
				maskRe: /([0-9]+)$/
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Sat',
			dataIndex: 'unit_id',
			width: 90,
			sortable: false,
			editor: rapkdet_unitField,
			renderer: Ext.util.Format.comboRenderer(rapkdet_unitField)
		},
		{
			header: '<div style="text-align: center">Harga</div>',
			dataIndex: 'rapkdet_price',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				allowNegative: false,
				blankText: '0',
				maxLength: 15,
				maskRe: /([0-9]+)$/
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: '<div style="text-align: center">Jumlah</div>',
			dataIndex: 'rapkdet_jumlah',
			width: 100,
			align: 'right',
			sortable: false,
			renderer: function(v, params, record){
				return Ext.util.Format.number(record.data.rapkdet_volume * record.data.rapkdet_price,'0.000/i');
            }
		},{
            xtype: 'booleancolumn',
            header: 'Tampilkan',
            dataIndex: 'rapkdet_publish',
            align: 'center',
            width: 50,
            trueText: 'Yes',
            falseText: 'No',
            editor: {
                xtype: 'checkbox'
            }
        }]
	);
	rapkdetColumnModel.defaultSortable= true;

	var total_rapkField = new Ext.form.NumberField({
		id: 'total_rapkField',
		allowNegatife : false,
		allowDecimals: false,
		hidden: true,
		value: 0,
		maskRe: /([0-9]+)$/
	});
	var editor_m_jobdet= new Ext.ux.grid.RowEditor({
        saveText: 'Update',
        clicksToEdit:2,
        listeners: {
        	'canceledit': function(){
        		var canceldata = rapkdetListGrid.getSelectionModel().getSelected().data;
            	total_rapkField.setValue(total_rapkField.getValue() + (canceldata.rapkdet_volume * canceldata.rapkdet_price));
            	
            	rapk_jobdet_name_selected.setValue(0);
            	rapk_jobdet_nameField.setValue(rapk_jobdet_name_field_temp.getValue());

            	var encoded_array_jobdet_id = Ext.encode(array_jobdet_id);

            	jobdet_allDataStore.setBaseParam('task', 'selected');
            	jobdet_allDataStore.setBaseParam('query', '');
        		jobdet_allDataStore.setBaseParam('selected_id', encoded_array_jobdet_id);
        		jobdet_allDataStore.load();
            },
            'beforeedit': function(){
            	var editdata = rapkdetListGrid.getSelectionModel().getSelected().data;
            	total_rapkField.setValue(total_rapkField.getValue() - (editdata.rapkdet_volume * editdata.rapkdet_price));
            	
            	rapk_jobdet_name_selected.setValue(0);
            	rapk_jobdet_name_field_temp.setValue(rapkdetListGrid.getSelectionModel().getSelected().get('jobdet_id'));

            	var encoded_array_jobdet_id = Ext.encode(array_jobdet_id);
            	
            	jobdet_allDataStore.setBaseParam('task', 'selected');
            	jobdet_allDataStore.setBaseParam('query', '');
        		jobdet_allDataStore.setBaseParam('selected_id', encoded_array_jobdet_id);
        		jobdet_allDataStore.load();
            },
            'afteredit': function(){
                var newdata = rapkdetListGrid.getSelectionModel().getSelected().data;
                
            	if((rapk_jobdet_name_selected.getValue()==1) 
                    	&& (/^\d+$/.test(rapkdetListGrid.getSelectionModel().getSelected().get('jobdet_id'))) 
                    	&& (array_jobdet_id.indexOf(rapkdetListGrid.getSelectionModel().getSelected().get('jobdet_id')) == (-1))){
            		array_jobdet_id.push(rapkdetListGrid.getSelectionModel().getSelected().get('jobdet_id'));
            	}
            	var encoded_array_jobdet_id = Ext.encode(array_jobdet_id);
            	
            	jobdet_allDataStore.setBaseParam('task', 'all');
            	jobdet_allDataStore.setBaseParam('query', '');
        		jobdet_allDataStore.setBaseParam('selected_id', encoded_array_jobdet_id);
        		jobdet_allDataStore.load();
        		rapk_jobdet_name_selected.setValue(0);


				var detail_total = 0;
        		
        		var detail_store = rapkdetListGrid.getStore();
        		for(var i=0;i<detail_store.getCount();i++){
            		var vol = detail_store.getAt(i).data.rapkdet_volume;
            		var hrg = detail_store.getAt(i).data.rapkdet_price;
            		if(vol !== undefined && hrg !== undefined){
            			detail_total+= (detail_store.getAt(i).data.rapkdet_volume * detail_store.getAt(i).data.rapkdet_price);
            		}
        			
        		}
        		total_rapkField.setValue(total_rapkField.getValue() + (newdata.rapkdet_volume * newdata.rapkdet_price));
        		//rapk_jobdet_total_cfField.setValue(formatCurrency(detail_total));
        		rapk_jobdet_total_cfField.setValue(formatCurrency(total_rapkField.getValue()));
				total_rapk = total_rapkField.getValue();
            }
        }
    });
	//detail list editor grid jobdet
	var rapkdetListGrid = new Ext.grid.EditorGridPanel({
		id: 'rapkdetListGrid',
		height: 250,
		autoScroll: true,
		store: jobdetDataStore, // DataStore
		colModel: rapkdetColumnModel, // Nama-nama Columns
		enableColLock:false,
		region: 'center',
        margins: '0 5 5 5',
		plugins: [editor_m_jobdet],
		frame: true,
		autoExpandColumn: 'jobdet_jenis_merk_ukuran',
		//clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:false},
		bbar: new Ext.PagingToolbar({
			pageSize: 10,
			store: jobdetDataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		{
			text: 'Add',
			tooltip: 'Add new detail record',
			iconCls:'icon-adds',    				// this is defined in our styles.css
			handler: m_jobdet_add
		}, '-',{
			text: 'Delete',
			tooltip: 'Delete detail selected record',
			iconCls:'icon-delete',
			handler: m_jobdet_confirm_delete
		}
		]
	});
	rapkdetListGrid.getColumnModel().setHidden(6, false);

	/* group of rapkdet [untuk sub-kontraktor] start */
	var group_rapkdetTempDataStore = new Ext.data.Store({
		id: 'group_rapkdetTempDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_rapk&m=t_rapkdet_grouptemp_getAll',
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total'
		},[
			{name: 'group_id', type: 'int', mapping: 'group_id'},
			{name: 'group_uraian', type: 'string', mapping: 'group_uraian'},
			{name: 'group_publish', type: 'bool', mapping: 'group_publish'}
		])
	});
	var group_rapkdet_publishTempColumn = new Ext.grid.CheckColumn({
		header: "Publish", 
		dataIndex: 'group_publish', 
		width: 80,
		hidden: false,
		sortable: false
	});
	var group_rapkdetTempColumnModel = new Ext.grid.ColumnModel(
		[new Ext.grid.RowNumberer(),{
			header: 'group_id',
			dataIndex: 'group_id',
			hidden: true
		},
		{
			header: 'Uraian',
			dataIndex: 'group_uraian',
			editor: new Ext.form.TextField({
				allowBlank: false,
				maxLength: 100
          	})
		},/*group_rapkdet_publishTempColumn*/
		{
            xtype: 'booleancolumn',
            header: 'Tampilkan',
            dataIndex: 'group_publish',
            align: 'center',
            width: 50,
            trueText: 'Yes',
            falseText: 'No',
			hidden:true,
            editor: {
                xtype: 'checkbox'
            },
			
			renderer: function(v, params, record){
				return 1;
			}
        }]
	);
	group_rapkdetTempColumnModel.defaultSortable= true;
	
	var editor_groupRapkdetTemp = new Ext.ux.grid.RowEditor({
        saveText: 'Update',
        clicksToEdit:2,
        listeners: {
        	'canceledit': function(){
            	group_detail_rapkdetTempListGrid.getStore().reload({
					callback: function(opts, success, response){
						group_detail_rapkdetTempListGrid.getSelectionModel().selectRow(0);
					}
				});
            },
            'beforeedit': function(){
                
            },
            'afteredit': function(){
                var newdata = group_detail_rapkdetTempListGrid.getSelectionModel().getSelected().data;
                
                Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_rapk&m=t_rapkdet_grouptemp_create',
					params: {
						group_id	: newdata.group_id,
						group_uraian	: newdata.group_uraian,
						group_publish	: newdata.group_publish
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								group_detail_rapkdetTempListGrid.getStore().reload({
									callback: function(opts, success, response){
										group_detail_rapkdetTempListGrid.getSelectionModel().selectRow(0);
									}
								});
								
								break;
							case 3:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: "Data gagal disimpan karena sesi anda telah habis. Silahkan login kembali.",
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING,
								   fn: function(btn) {
										if (btn == 'ok') {
											window.location='index.php?c=main';
										}
									}, 
								});
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
            }
        }
    });

	var group_detail_rapkdetTempListGrid = new Ext.grid.EditorGridPanel({
		id: 'group_detail_rapkdetTempListGrid',
        frame: true,
        title: 'Groups',
        height: 150,
        store: group_rapkdetTempDataStore,
        plugins: [editor_groupRapkdetTemp],
        colModel : group_rapkdetTempColumnModel,
        enableColLock:false,
        selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
        tbar: [{
            text: 'Add',
            iconCls: 'icon-adds',
            handler: group_rapkdet_temp_add
        }, '-', {
            text: 'Delete',
            iconCls: 'icon-delete',
            handler: group_rapkdet_temp_delete
        }, '-'],
        viewConfig: {
            forceFit: true
        }
    });
	
	group_detail_rapkdetTempListGrid.on('afteredit', function(evt){
		var newdata = group_detail_rapkdetTempListGrid.getSelectionModel().getSelected().data;

                Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_rapk&m=t_rapkdet_grouptemp_create',
					params: {
						group_id	: newdata.group_id,
						group_uraian	: newdata.group_uraian,
						group_publish	: newdata.group_publish
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								group_detail_rapkdetTempListGrid.getStore().reload({
									callback: function(opts, success, response){
										group_detail_rapkdetTempListGrid.getSelectionModel().selectRow(0);
									}
								});
								
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
	});
	
	group_detail_rapkdetTempListGrid.getSelectionModel().on('rowselect', function(sm, rowIdx, r){

		var rapkdettemp = detail_rapkdetTempListGrid.getStore();
		rapkdettemp.setBaseParam('group_id', sm.getSelected().get('group_id'));
		rapkdettemp.load();
		
		if(group_detail_rapkdetTempListGrid.getSelectionModel().getCount() == 1){
			detail_rapkdetTempListGrid.rapkdettempAddBtn.enable();
			detail_rapkdetTempListGrid.rapkdettempDeleteBtn.enable();
		}
	});
	
	function group_rapkdet_temp_delete(){
		// only one record is selected here
		if(group_detail_rapkdetTempListGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod ini?', group_rapkdet_temp_confirm_delete);
		} else if(group_detail_rapkdetTempListGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod-rekod ini?', group_rapkdet_temp_confirm_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Tidak ada data yang terpilih untuk diupdate',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}4
	
//	 rapkdet temp [untuk sub-kontraktor] start 
	var rapkdetTempDataStore = new Ext.data.Store({
		id: 'rapkdetTempDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_rapk&m=t_rapkdet_groupdettemp_getAll',
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total'
		},[
			{name: 'groupdettemp_id', type: 'int', mapping: 'groupdettemp_id'}, 
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'}, 
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'rapkdet_volume', type: 'float', mapping: 'rapkdet_volume'},
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'},
			{name: 'rapkdet_price', type: 'float', mapping: 'rapkdet_price'},
			{name: 'rapkdet_publish', type: 'bool', mapping: 'rapkdet_publish'}
		])
}); 

	var ProcurementDataStore = new Ext.data.Store({
		id: 'ProcurementDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_procurement',
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total'
		},[
			{name: 'procurement_name', type: 'text', mapping: 'procurement_name'}
		])
	}); 

	var gettotalDataStore = new Ext.data.Store({
		id: 'ProcurementDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_rapk&m=get_rapktotal',
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total'
		},[
			{name: 'total', type: 'float', mapping: 'total'}
		])
	}); 

	function group_rapkdet_temp_add(btn, ev) {
        var editor = new group_detail_rapkdetTempListGrid.store.recordType({
            group_id : 0,
            group_uraian: ''
        });
        editor_groupRapkdetTemp.stopEditing();
        group_detail_rapkdetTempListGrid.store.insert(0, editor);
		//group_detail_rapkdetTempListGrid.getView().refresh();
		group_detail_rapkdetTempListGrid.getSelectionModel().selectRow(0);
		editor_groupRapkdetTemp.startEditing(0);
    }
	
	function group_rapkdet_temp_confirm_delete(btn){
		if(btn=='yes'){
			var s = group_detail_rapkdetTempListGrid.getSelectionModel().getSelections();
			for(var i = 0, r; r = s[i]; i++){
				//group_detail_rapkdetTempListGrid.getStore().remove(r);
				
				// delete group rapkdet
				 
				
				var newdata = group_detail_rapkdetTempListGrid.getSelectionModel().getSelected().data;
                
                Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_rapk&m=t_rapkdet_grouptemp_delete',
					params: {
						group_id	: r.data.group_id
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								group_detail_rapkdetTempListGrid.getStore().reload({
									callback: function(opts, success, response){
										group_detail_rapkdetTempListGrid.getSelectionModel().selectRow(0);
									}
								});
								
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
			}
			
			detail_rapkdetTempListGrid.rapkdettempAddBtn.disable();
			detail_rapkdetTempListGrid.rapkdettempDeleteBtn.disable();
		}  
	} 

	var rapkdetTempColumnModel = new Ext.grid.ColumnModel(
		[{
			header: 'rapkdet_id',
			dataIndex: 'rapkdet_id',
			hidden: true
		},
		{
			header: 'Jenis, Merk, dan Ukuran Material',
			id: 'jobdet_jenis_merk_ukuran',
			dataIndex: 'jobdet_id',
			editor: rapk_jobdet_nameField,
			renderer: Ext.util.Format.comboRenderer(rapk_jobdet_nameField)
		},
		{
			header: '<div style="text-align: center">Vol</div>',
			dataIndex: 'rapkdet_volume',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				allowNegative: false,
				blankText: '0',
				maxLength: 10,
				maskRe: /([0-9]+)$/
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Sat',
			dataIndex: 'unit_id',
			width: 90,
			sortable: false,
			editor: rapkdet_unitField,
			renderer: Ext.util.Format.comboRenderer(rapkdet_unitField)
		},
		{
			header: '<div style="text-align: center">Harga</div>',
			dataIndex: 'rapkdet_price',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				allowNegative: false,
				blankText: '0',
				maxLength: 15,
				maskRe: /([0-9]+)$/
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: '<div style="text-align: center">Jumlah</div>',
			dataIndex: 'rapkdet_jumlah',
			width: 100,
			align: 'right',
			sortable: false,
			renderer: function(v, params, record){
				return Ext.util.Format.number(record.data.rapkdet_volume * record.data.rapkdet_price,'0.000/i');
            }
		},{

            xtype: 'booleancolumn',
            header: 'Tampilkan',
            dataIndex: 'rapkdet_publish',
            align: 'center',
            width: 50,
            trueText: 'Yes',
            falseText: 'No',
            editor: {
                xtype: 'checkbox'
            }
        }]
	);
	rapkdetTempColumnModel.defaultSortable= true;	
	var editor_groupdetRapkdetTemp = new Ext.ux.grid.RowEditor({
        saveText: 'Update', 
        clicksToEdit:2,
        listeners: {
        	'canceledit': function(){
			
				detail_rapkdetTempListGrid.getStore().reload({
					callback: function(opts, success, response){
						detail_rapkdetTempListGrid.getSelectionModel().selectRow(0);
					} //di sini
				});
				
        		var canceldata = detail_rapkdetTempListGrid.getSelectionModel().getSelected().data;
            	total_rapkField.setValue(total_rapkField.getValue() + (canceldata.rapkdet_volume * canceldata.rapkdet_price));
            	
            	rapk_jobdet_name_selected.setValue(0);
            	rapk_jobdet_nameField.setValue(rapk_jobdet_name_field_temp.getValue());

            	var encoded_array_jobdet_id = Ext.encode(array_jobdet_id);

            	jobdet_allDataStore.setBaseParam('task', 'selected');
            	jobdet_allDataStore.setBaseParam('query', '');
        		jobdet_allDataStore.setBaseParam('selected_id', encoded_array_jobdet_id);
        		jobdet_allDataStore.load();
            },
            'beforeedit': function(){
            	var editdata = detail_rapkdetTempListGrid.getSelectionModel().getSelected().data;
            	total_rapkField.setValue(total_rapkField.getValue() - (editdata.rapkdet_volume * editdata.rapkdet_price));
            	
            	rapk_jobdet_name_selected.setValue(0);
            	rapk_jobdet_name_field_temp.setValue(detail_rapkdetTempListGrid.getSelectionModel().getSelected().get('jobdet_id'));

            	var encoded_array_jobdet_id = Ext.encode(array_jobdet_id);
            	
            	jobdet_allDataStore.setBaseParam('task', 'selected');
            	jobdet_allDataStore.setBaseParam('query', '');
        		jobdet_allDataStore.setBaseParam('selected_id', encoded_array_jobdet_id);
        		jobdet_allDataStore.load();
            },
            'afteredit': function(){
                var newdata = detail_rapkdetTempListGrid.getSelectionModel().getSelected().data;
                
            	if((rapk_jobdet_name_selected.getValue()==1) 
                    	&& (/^\d+$/.test(detail_rapkdetTempListGrid.getSelectionModel().getSelected().get('jobdet_id'))) 
                    	&& (array_jobdet_id.indexOf(detail_rapkdetTempListGrid.getSelectionModel().getSelected().get('jobdet_id')) == (-1))){
            		array_jobdet_id.push(detail_rapkdetTempListGrid.getSelectionModel().getSelected().get('jobdet_id'));
            	}
            	var encoded_array_jobdet_id = Ext.encode(array_jobdet_id);
            	
            	jobdet_allDataStore.setBaseParam('task', 'all');
            	jobdet_allDataStore.setBaseParam('query', '');
        		jobdet_allDataStore.setBaseParam('selected_id', encoded_array_jobdet_id);
        		jobdet_allDataStore.load();
        		rapk_jobdet_name_selected.setValue(0);

			/*	
				var detail_total = 0;
        		
        		var detail_store = detail_rapkdetTempListGrid.getStore();
        		for(var i=0;i<detail_store.getCount();i++){
            		var vol = detail_store.getAt(i).data.rapkdet_volume;
            		var hrg = detail_store.getAt(i).data.rapkdet_price;
            		if(vol !== undefined && hrg !== undefined){
            			detail_total+= (detail_store.getAt(i).data.rapkdet_volume * detail_store.getAt(i).data.rapkdet_price);
            		}
        		} */
				// disini !
        	//	total_rapkField.setValue(total_rapkField.getValue() + (newdata.rapkdet_volume * newdata.rapkdet_price));
        		//rapk_jobdet_total_cfField.setValue(formatCurrency(detail_total));


        		/*
        		 * insert t_rapkdet_groupdettemp
       		 	 */
       		 	var group = group_detail_rapkdetTempListGrid.getSelectionModel().getSelected().data;
                Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_rapk&m=t_rapkdet_groupdettemp_create',
					params: {
						group_id		: group.group_id,
						m_jobdet_id		: newdata.jobdet_id,
						rapkdet_volume	: newdata.rapkdet_volume,
						rapkdet_unit	: newdata.unit_id,
						rapkdet_price	: newdata.rapkdet_price,
						rapkdet_publish	: newdata.rapkdet_publish,
						groupdettemp_id : newdata.groupdettemp_id
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								detail_rapkdetTempListGrid.getStore().reload();
									gettotalDataStore.load({
										callback : function(){
											rapk_jobdet_total_cfField.setValue(formatCurrency(gettotalDataStore.getAt(0).data.total ));
											total_rapk = gettotalDataStore.getAt(0).data.total;
										}
									});
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
            }
        }
    });
	var detail_rapkdetTempListGrid = new Ext.grid.EditorGridPanel({
		id: 'detail_rapkdetTempListGrid',
        frame: true,
        //title: 'Groups',
        height: 250,
        store: rapkdetTempDataStore,
        plugins: [editor_groupdetRapkdetTemp],
        colModel : rapkdetTempColumnModel,
        enableColLock:false,
        selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
        tbar: [{
            text: 'Add',
            ref: '../rapkdettempAddBtn',
            iconCls: 'icon-adds',
            disabled: true,
            handler: rapkdet_temp_add
        }, '-', {
            text: 'Delete',
            ref: '../rapkdettempDeleteBtn',
            iconCls: 'icon-delete',
            disabled: true,
            handler: rapkdet_temp_delete
        }, '-'],
        viewConfig: {
            forceFit: true
        }
    });
	//detail_rapkdetTempListGrid.rapkdettempAddBtn.disabled = false;

	function rapkdet_temp_add(btn, ev) {
		var editor_rapkdettemp= new detail_rapkdetTempListGrid.store.recordType({
			rapkdet_id: 0,
			jobdet_id: '',
			rapkdet_volume: 0,
			rapkdet_unit: '',
			rapkdet_price: 0
		});
		editor_groupdetRapkdetTemp.stopEditing();
		rapkdetTempDataStore.insert(0, editor_rapkdettemp);
		//detail_rapkdetTempListGrid.getView().refresh();
		detail_rapkdetTempListGrid.getSelectionModel().selectRow(0);
		editor_groupdetRapkdetTemp.startEditing(0);
	}
	
	function rapkdet_temp_delete(){
		// only one record is selected here
		if(detail_rapkdetTempListGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod ini?', rapkdet_temp_confirm_delete);
		} else if(detail_rapkdetTempListGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod-rekod ini?', rapkdet_temp_confirm_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Tidak ada data yang terpilih untuk diupdate',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	
	function rapkdet_temp_confirm_delete(btn){
		if(btn=='yes'){
			var rdata = null;
			var s = rapkdetListGrid.getSelectionModel().getSelections();
			for(var i = 0, r; r = s[i]; i++){
				rdata = r.data;
				jobdetDataStore.remove(r);
			}
			
	
			var detail_total = 0;
			
			var detail_store = rapkdetListGrid.getStore();
			for(var i=0;i<detail_store.getCount();i++){
	    		var vol = detail_store.getAt(i).data.rapkdet_volume;
	    		var hrg = detail_store.getAt(i).data.rapkdet_price;
	    		if(vol !== undefined && hrg !== undefined){
	    			detail_total+= (detail_store.getAt(i).data.rapkdet_volume * detail_store.getAt(i).data.rapkdet_price);
	    		}
				
			}
			//rapk_jobdet_total_cfField.setValue(formatCurrency(detail_total));
			total_rapkField.setValue(total_rapkField.getValue() - (rdata.rapkdet_volume * rdata.rapkdet_price));
			rapk_jobdet_total_cfField.setValue(formatCurrency(total_rapkField.getValue()));
			total_rapk = total_rapkField.getValue();
		}  
	}
	/* rapkdet temp [untuk sub-kontraktor] end */
 
	function rapkdet_temp_add(btn, ev) {
		var editor_rapkdettemp= new detail_rapkdetTempListGrid.store.recordType({
			rapkdet_id: 0,
			jobdet_id: '',
			rapkdet_volume: 0,
			rapkdet_unit: '',
			rapkdet_price: 0
		});
		editor_groupdetRapkdetTemp.stopEditing();
		rapkdetTempDataStore.insert(0, editor_rapkdettemp);
		//detail_rapkdetTempListGrid.getView().refresh();
		detail_rapkdetTempListGrid.getSelectionModel().selectRow(0);
		editor_groupdetRapkdetTemp.startEditing(0);
	}
	
	function rapkdet_temp_delete(){
		// only one record is selected here
		if(detail_rapkdetTempListGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod ini?', rapkdet_temp_confirm_delete);
		} else if(detail_rapkdetTempListGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod-rekod ini?', rapkdet_temp_confirm_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Tidak ada data yang terpilih untuk diupdate',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	
	function rapkdet_temp_confirm_delete(btn){
		if(btn=='yes'){
			if (detail_rapkdetTempListGrid.isVisible()){
				grid = detail_rapkdetTempListGrid;
				var itemsdelete = [];
			}else{
				grid = rapkdetListGrid;
			}
			var rdata = null;
			var s = grid.getSelectionModel().getSelections();
			for(var i = 0, r; r = s[i]; i++){
				rdata = r.data;
				master_store = grid.getStore();
				master_store.remove(r);
				if (detail_rapkdetTempListGrid.isVisible()){
					itemsdelete.push(r.data.groupdettemp_id);
				}
			}
			if (detail_rapkdetTempListGrid.isVisible()){
				
				Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_rapk&m=t_rapkdet_detailtemp_delete',
					params: {
						ids	:  Ext.encode(itemsdelete)
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
			}
			
			var detail_total = 0;
			
			var detail_store = grid.getStore();
			for(var i=0;i<detail_store.getCount();i++){
	    		var vol = detail_store.getAt(i).data.rapkdet_volume;
	    		var hrg = detail_store.getAt(i).data.rapkdet_price;
	    		if(vol !== undefined && hrg !== undefined){
	    			detail_total+= (detail_store.getAt(i).data.rapkdet_volume * detail_store.getAt(i).data.rapkdet_price);
	    		}
				
			}
			//rapk_jobdet_total_cfField.setValue(formatCurrency(detail_total));
			total_rapkField.setValue(total_rapkField.getValue() - (rdata.rapkdet_volume * rdata.rapkdet_price));
			rapk_jobdet_total_cfField.setValue(formatCurrency(total_rapkField.getValue()));
			total_rapk = total_rapkField.getValue();
			gettotalDataStore.load({
					callback : function(){
						rapk_jobdet_total_cfField.setValue(formatCurrency(gettotalDataStore.getAt(0).data.total ));
						total_rapk = gettotalDataStore.getAt(0).data.total;
				}
			});
		}  
	}
	/* rapkdet temp [untuk sub-kontraktor] end */
	
	var rapkdet_jobdetGroup = new Ext.form.FieldSet({
		title: 'Detail Jenis Pekerjaan',
		labelWidth: 140,
		autoHeight: true,
		collapsible: true,
		layout:'form',
		frame: false,
		hidden: true,
		items:[group_detail_rapkdetTempListGrid, detail_rapkdetTempListGrid, rapkdetListGrid]
	});

	//Form Create/Update
	var rapk_idField= new Ext.form.NumberField({
		id: 'rapk_idField',
		fieldLabel: 'RAPK Id ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	var rapk_branchField= new Ext.form.ComboBox({
		id: 'rapk_branchField',
		fieldLabel: 'Cabang <font color=red>*</font>',
		store: branchDataStore,
		mode: 'remote',
		displayField:'branch_name',
		valueField: 'branch_id',
        editable: false,
        forceSelection: true,
        anchor: '95%',
		pageSize: 15,
		triggerAction: 'all',
		/*getDisplayValue: function() {
	        return Ext.String.htmlDecode(this.value);
	    }*/
		/*listeners: {
			select: function(){
				this.displayField(Ext.util.Format.htmlDecode(this.getRawValue()));
			}
		}*/
	});
	rapk_branchField.on('select', function(){
		rapk_branchField.disable();
		project_codeDataStore.setBaseParam('branch_id', rapk_branchField.getValue());
		project_codeDataStore.load();
	});
	var rapk_projectField= new Ext.form.ComboBox({
		id: 'rapk_projectField',
		fieldLabel: 'Kode Proyek',
		store: project_codeDataStore,
		mode: 'local',
		displayField:'project_code',
		valueField: 'project_id',
        editable: true,
        anchor: '95%',
		pageSize: 15,
		itemSelector: 'div.search-item',
		tpl: tpl_projectDS,
		triggerAction: 'all'
	});
	rapk_projectField.on('select', function(){
		var record = rapk_projectField.findRecord(rapk_projectField.valueField, rapk_projectField.getValue());
		//rapk_projectNameField.setValue(record.get(rapk_projectField.displayField));
		rapk_projectNameField.setValue(record.data.project_name);

		//jobDataStore.setBaseParam('div_id', record.data.div_id);
		//jobDataStore.load();
	});
	var rapk_projectNameField= new Ext.form.TextField({
		id: 'rapk_projectNameField',
		fieldLabel: 'Nama Proyek',
		width: 250,
		readOnly: true
	});
	var rapk_divField = new Ext.form.ComboBox({
		id: 'rapk_divField',
		fieldLabel: 'Jenis Biaya',
		store: divDataStore,
		editable : false,
		mode: 'remote',
		displayField:'div_name',
		valueField: 'div_id',
        anchor: '95%',
		pageSize: 15,
		triggerAction: 'all'
	});
	rapk_divField.on('select', function(){
		jobDataStore.setBaseParam('div_id', rapk_divField.getValue());
		jobDataStore.load({
			callback : function(){

				 if (jobDataStore.data.length == 0){
					rapk_jobField.reset();
					rapk_jobField.setEditable(false);
				}else{
					rapk_jobField.setEditable(true);
				}
			}
		});
	});
	var rapk_jobField = new Ext.form.ComboBox({
		id: 'rapk_jobField',
		fieldLabel: 'Jenis Pekerjaan',
		store: jobDataStore,
		mode: 'local',
		displayField:'job_name',
		valueField: 'job_id',
        editable: false,
        anchor: '95%',
		pageSize: 15,
		triggerAction: 'all'
	});
	
	
	var rapk_procurementField = new Ext.form.ComboBox({
		id: 'rapk_procurementField',
		fieldLabel: 'Procurement',
		store: ProcurementDataStore,
		displayField:'procurement_name',
		valueField: 'procurement_name',
        editable: true,
        anchor: '95%',
		pageSize: 15,
		editable : false,
		triggerAction: 'all'
	});
	
	rapk_jobField.on('select', function(){
		var record = rapk_divField.findRecord(rapk_divField.valueField, rapk_divField.getValue());
		var record_job = rapk_jobField.findRecord(rapk_jobField.valueField, rapk_jobField.getValue());
		var_job_id = record_job.data.job_id;

		//show-hide untuk Sub-Kontraktor
		if(record.data.div_name != '503. Sub Kontraktor'){
			//supplier
			rapkdetListGrid.show();
			rapkdetListGrid.getColumnModel().setHidden(6, true);
			group_detail_rapkdetTempListGrid.hide();
			detail_rapkdetTempListGrid.hide();
			
		}else{
			//sub-kontraktor
			//rapkdetListGrid.getColumnModel().setHidden(6, false);
			rapkdetListGrid.hide();
			if(post2db == 'CREATE'){
				group_detail_rapkdetTempListGrid.show();
				detail_rapkdetTempListGrid.show();
			}else{
				
			}
		}
		rapkdet_jobdetGroup.show();
		
		jobdet_allDataStore.setBaseParam('task', 'detail');
		jobdet_allDataStore.setBaseParam('query', '');
		jobdet_allDataStore.setBaseParam('master_id', rapk_jobField.getValue());
		jobdet_allDataStore.load({
			callback: function(opts, success, response){
				jobdetDataStore.setBaseParam('master_id', rapk_jobField.getValue());
				jobdetDataStore.setBaseParam('start', 0);
				jobdetDataStore.setBaseParam('limit', 10);
				jobdetDataStore.setBaseParam('task', 'byjob');
				jobdetDataStore.load();

				for(var i=0; i<jobdet_allDataStore.getCount();i++){
					array_jobdet_id.push(jobdet_allDataStore.getAt(i).data.jobdet_id);
	            }
			}
		});

		
	});
	
	var t_rapk_btn_Save = new Ext.Button({
		text: BTN_SAVE,
		handler: t_rapk_save
	});
	t_rapk_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		title: TITLE_FORM+' RAPK',
		bodyStyle:'padding:5px',
		autoHeight:true,
		width: 900,
		collapsible: true,
		frame: true,
		renderTo: 'elwindow_t_rapk_save',
		layout:'form',
		items:[{
			layout: 'column',
			border: false,
			items:[{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[rapk_idField ,rapk_branchField ,rapk_projectField ,rapk_projectNameField]
			},{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [rapk_divField ,rapk_jobField,rapk_procurementField]
			}]
		},rapkdet_jobdetGroup ,rapk_jobdet_totalGroup,new  Ext.form.Label({html:'Keterangan : <br /><br><font color=red>*</font>  '+INFO_REQUIRED
		+'<br />tampilkan jika dicentang maka ditampilkan di komparasi, po dan kontrak' })],
		buttons: [t_rapk_btn_Save, 
		  	{
				text: BTN_CANCEL,
				handler: function(){
					t_rapk_reset_form();
				}
			}
		]
	});
	
	//start main grid panel
	t_rapk_ColumnModel = new Ext.grid.ColumnModel(
		[{
			header: 'RAPK Id',
			dataIndex: 'rapk_id',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Cabang',
			dataIndex: 'branch_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Kode Proyek',
			dataIndex: 'project_code',
			width: 150,
			sortable: false
		},
		{
			header: 'Nama Proyek',
			dataIndex: 'project_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Jenis Pekerjaan',
			dataIndex: 'job_name',
			width: 150,
			sortable: false
		}	]);

	t_rapk_ColumnModel.defaultSortable= true;
	/* End of Function */

    /* Button Control */
    t_rapk_gbtn_add=new Ext.Button({
	    text: BTN_ADD_TITLE,
		tooltip: BTN_ADD_TOOLTIP,
		iconCls:'icon-adds',
		handler: display_form_window
    });

    t_rapk_gbtn_update=new Ext.Button({
	    text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: t_rapk_confirm_update
	});

    t_rapk_gbtn_delete=new Ext.Button({
	    text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: t_rapk_confirm_delete
	});

	t_rapk_ListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 't_rapk_ListEditorGrid',
		el: 'fp_t_rapk',
		title: TITLE_LIST,
		autoHeight: true,
		collapsible: true,
		store: t_rapk_DataStore, // DataStore
		cm: t_rapk_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
	  	width: 1024,
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: t_rapk_DataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		t_rapk_gbtn_add, '-',
		t_rapk_gbtn_update, '-',
		t_rapk_gbtn_delete, '-',
		new Ext.app.SearchField({
			store: t_rapk_DataStore,
			listeners:{
				specialkey: function(f,e){
					if(e.getKey() == e.ENTER){
						t_rapk_DataStore.baseParams={task:'LIST', start:0, limit:pageS};
		            }
				},
				render: function(c){
				Ext.get(this.id).set({qtitle: BTN_SIMPLE_SEARCH_TOOLTIP});
				}
			},
			width: 120
		}),'-',{
			text: BTN_REFRESH_TITLE,
			tooltip: BTN_REFERSH_TOOLTIP,
			handler: t_rapk_reset_search,
			iconCls:'icon-refresh'
		}/*,'-',{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: t_rapk_export_excel
		}*/
		]
	});
	t_rapk_ListEditorGrid.render();
	
  	/* END FORM */
  	
  	
  	/* START FUNCTION */
	function get_pk_id(){
		if(post2db=='UPDATE')
			return t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('rapk_id');
		return 0;
	}
	
	//validation form
	function is_t_rapk_form_valid(){
		return (true);
	}
	
	//saving data
	function t_rapk_save(){
		var patt=new RegExp("U");
		var patt2=new RegExp("C");
		if(patt.test(PERMISSION)==false && patt2.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{
	
			if(is_t_rapk_form_valid()){
				
				var rapk_id_field=null;
				var rapk_branch_field=null;
				var rapk_project_field=null;
				var rapk_job_field=null;
				var rapk_procurement_field=null;
				var rapk_total_field = null;
				// disini
				if(rapk_idField.getValue()!== null){rapk_id_field = rapk_idField.getValue();}
				if(rapk_branchField.getValue()!== null){rapk_branch_field = rapk_branchField.getValue();}
				if(rapk_projectField.getValue()!== null){rapk_project_field = rapk_projectField.getValue();}
				rapk_job_field = var_job_id;
				if(rapk_procurementField.getValue()!== null){rapk_procurement_field = rapk_procurementField.getValue();}
				if(total_rapk !== null){rapk_total_field = total_rapk;}
			
				//push data detail --> supplier
		//		if (rapk_divField.getValue() == 1){
					var rapkdet_id_field = [];
					var jobdet_id_field = [];
					var jobdet_name_field = [];
					var rapkdet_volume_field = [];
					var rapkdet_unit_field = [];
					var rapkdet_price_field = [];
					var jobdet_store = rapkdetListGrid.getStore();
					for(var i=0; i<jobdet_store.getCount(); i++){
						if(jobdet_store.getAt(i).data.jobdet_id!==undefined
								&& jobdet_store.getAt(i).data.jobdet_id!==''){
							rapkdet_id_field.push(jobdet_store.getAt(i).data.rapkdet_id);
							jobdet_id_field.push(jobdet_store.getAt(i).data.jobdet_id);
							jobdet_name_field.push(jobdet_store.getAt(i).data.jobdet_name);
							rapkdet_volume_field.push(jobdet_store.getAt(i).data.rapkdet_volume);
							rapkdet_unit_field.push(jobdet_store.getAt(i).data.unit_id);
							rapkdet_price_field.push(jobdet_store.getAt(i).data.rapkdet_price);
						}
					}
					var encoded_array_rapkdet_id = Ext.encode(rapkdet_id_field);
					var encoded_array_jobdet_id = Ext.encode(jobdet_id_field);
					var encoded_array_jobdet_name = Ext.encode(jobdet_name_field);
					var encoded_array_rapkdet_volume = Ext.encode(rapkdet_volume_field);
					var encoded_array_rapkdet_unit = Ext.encode(rapkdet_unit_field);
					var encoded_array_rapkdet_price = Ext.encode(rapkdet_price_field);
		//		}
				// var encoded_array_detailpekerjaan = Ext.encode(arr_detailpekerjaan);
				//var encoded_array_parentcheckfield = Ext.encode(arr_parentcheckfield);
if (post2db != 'UPDATE'){
	if (! (Ext.isNumber( rapk_project_field) ) ) {Ext.Msg.alert('Warning','Inputan Kode Project tidak benar!'); return false; };
	if (! (Ext.isNumber( rapk_job_field) ) ) {Ext.Msg.alert('Warning','Inputan Jenis Pekerjaan tidak benar!'); return false; };
	if ( rapk_procurement_field == "" ) {Ext.Msg.alert('Warning','Inputan Procurement tidak benar!'); return false; };
}

				//push data detail

				//var encoded_array_detailpekerjaan = Ext.encode(arr_detailpekerjaan);
				//var encoded_array_parentcheckfield = Ext.encode(arr_parentcheckfield);


 				Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_rapk&m=get_action',
					params: {
						rapk_id	: rapk_id_field,
						branch	: rapk_branch_field,
						project	: rapk_project_field,
						job	: rapk_job_field,
						rapk_total : rapk_total_field ,
						procurement : rapk_procurement_field,
						div_id : rapk_divField.getRawValue(),
						jobdet_id : encoded_array_jobdet_id,
						jobdet_name : encoded_array_jobdet_name,
						rapkdet_volume : encoded_array_rapkdet_volume,
						rapkdet_unit : encoded_array_rapkdet_unit,
						rapkdet_price : encoded_array_rapkdet_price,
						rapkdet_id : encoded_array_rapkdet_id,
						//detailpekerjaan: encoded_array_detailpekerjaan,
						//parentcheck: encoded_array_parentcheckfield,

						
						//detailpekerjaan: encoded_array_detailpekerjaan,
						//parentcheck: encoded_array_parentcheckfield,

						task: post2db
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								t_rapkdet_grouptemp_truncate();
								Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
								t_rapk_DataStore.reload();
								t_rapk_reset_form();
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				}); 
	
			} else {
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_VALID_FORM,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
			}

		}
	}
	
	//reset form
	function t_rapk_reset_form(){
		post2db = 'CREATE';
		
		rapk_branchField.enable();
		rapk_idField.reset();
		rapk_idField.setValue(null);
		rapk_projectField.reset();
		rapk_projectField.setValue(null);
		rapk_projectField.enable();
		rapk_projectNameField.reset();
		rapk_projectNameField.setValue(null);
		rapk_branchField.reset();
		rapk_branchField.setValue(null);
		rapk_branchField.enable();
		rapk_jobdet_total_cfField.reset();
		rapk_jobdet_total_cfField.setValue(null);
		total_rapk = 0;
		rapk_divField.reset();
		rapk_divField.setValue(null);
		rapk_divField.enable();
		rapk_jobField.reset();
		rapk_jobField.setValue(null);
		rapk_jobField.enable();
		
		rapk_procurementField.reset();
		rapk_procurementField.setValue(null);
		rapk_procurementField.enable();
		
		rapkdetListGrid.getStore().removeAll();
		group_detail_rapkdetTempListGrid.getStore().removeAll();
		detail_rapkdetTempListGrid.getStore().removeAll();
		
		rapkdetListGrid.hide();
		group_detail_rapkdetTempListGrid.hide();
		detail_rapkdetTempListGrid.hide();
		
		rapkdetListGrid.getColumnModel().setHidden(6, true);
	}
	
	//set form
	function t_rapk_set_form(){
		rapk_idField.setValue(t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('rapk_id'));
		rapk_branchField.setValue(t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('branch_name'));
		rapk_branchField.disable();
		rapk_projectField.setValue(t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('project_code'));
		rapk_projectField.disable();
		rapk_projectNameField.setValue(t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('project_name'));
		rapk_divField.setValue(t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('div_name'));
		rapk_divField.disable();
		var_job_id = rapk_jobField.setValue(t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('job_id'));
		rapk_jobField.setValue(t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('job_name'));
		rapk_jobField.disable();
		rapk_procurementField.setValue(t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('rapk_procurement'));
		rapk_procurementField.disable();
		
		//show-hide untuk Sub-Kontraktor
							
		if(t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('div_name') != '503. Sub Kontraktor'){
		
			unitDataStore.load({
			callback: function(opts, success, response){
				jobdet_allDataStore.load({
					callback: function(opts, success, response){
						var detail_store = rapkdetListGrid.getStore();
						detail_store.setBaseParam('master_id', t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('rapk_id'));
						detail_store.setBaseParam('start', 0);
						detail_store.setBaseParam('limit', 15);
						detail_store.setBaseParam('task', 'detail');
						detail_store.load({
							callback: function(opts, success, response){
 								var detail_total = 0;
								for(var i=0; i<detail_store.getCount(); i++){
									detail_total += (detail_store.getAt(i).data.rapkdet_volume * detail_store.getAt(i).data.rapkdet_price);

									array_jobdet_id.push(detail_store.getAt(i).data.jobdet_id);
								}
								total_rapkField.setValue(detail_total);
								rapk_jobdet_total_cfField.setValue(formatCurrency(detail_total)); 
								total_rapk = detail_total;
							}
						});
					}
				});
			}
		});
		
			//supplier
			rapkdetListGrid.show();
			rapkdetListGrid.getColumnModel().setHidden(6, true);
			group_detail_rapkdetTempListGrid.hide();
			detail_rapkdetTempListGrid.hide();
		}else{
			//sub-kontraktor
			rapkdetListGrid.getColumnModel().setHidden(6, false);
			rapkdetListGrid.hide();
			if(post2db == 'CREATE'){
				group_detail_rapkdetTempListGrid.show();
				detail_rapkdetTempListGrid.show();
			}else{
				//	ini jika update // edited by unu
				
				group_detail_rapkdetTempListGrid.show();
				detail_rapkdetTempListGrid.show();
			rapk_id = t_rapk_ListEditorGrid.getSelectionModel().getSelected().get('rapk_id');
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_t_rapk&m=get_action',
				params: { task: "EDIT_SUBKON", rapk_id:  rapk_id },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
						//	var rapkdettemp = detail_rapkdetTempListGrid.getStore();
							unitDataStore.load({
							callback: function(opts, success, response){
								jobdet_allDataStore.load({
									callback: function(opts, success, response){
											group_rapkdetTempDataStore.load();
											rapkdetTempDataStore.load();
										}
									});
								}
							});
							gettotalDataStore.load({
								callback : function(){
								console.log(gettotalDataStore.getAt(0).data.total);
								rapk_jobdet_total_cfField.setValue(formatCurrency(gettotalDataStore.getAt(0).data.total ));
								total_rapk = gettotalDataStore.getAt(0).data.total;
								}
							});
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: 'Gagal ambil data!',
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});
				}
			});

			}

			rapkdetListGrid.getColumnModel().setHidden(6, false);
			rapkdetListGrid.hide();
			if(post2db == 'CREATE'){
				group_detail_rapkdetTempListGrid.show();
				detail_rapkdetTempListGrid.show();
			}else{
				
			}

		}
		rapkdet_jobdetGroup.show();
		
	}
	
	//display form to create/update
	function display_form_window(){
		t_rapkdet_grouptemp_truncate();
		post2db='CREATE';
		msg='created';
		t_rapk_reset_form();
	}
	
	//update main grid
	function t_rapk_confirm_update(){
		/* only one record is selected here */
		if(t_rapk_ListEditorGrid.selModel.getCount() == 1) {
			post2db='UPDATE';
			msg='updated';
			t_rapk_set_form();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_UPDATE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	
	//delete main grid
	function t_rapk_confirm_delete(){
		// only one t_rapk is selected here
		if(t_rapk_ListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_DELETE, t_rapk_delete);
		} else if(t_rapk_ListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_MULTI_DELETE, t_rapk_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_DELETE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	function t_rapk_delete(btn){
		if(btn=='yes'){

		var patt=new RegExp("D");
		if(patt.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

			var selections = t_rapk_ListEditorGrid.selModel.getSelections();
			var prez = [];
			for(var i = 0; i< t_rapk_ListEditorGrid.selModel.getCount(); i++){
				prez.push(selections[i].json.rapk_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_t_rapk&m=get_action',
				params: { task: "DELETE", ids:  encoded_array },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							t_rapk_DataStore.reload();
							break;
						case 3:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: 'Data ini sudah diproses tidak bisa dihapus',
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: FAILED_DELETE,
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});
				}
			});

			}

		}
	}
	
	//reset searching
	function t_rapk_reset_search(){
		t_rapk_DataStore.baseParams = { task: 'LIST' };
		t_rapk_DataStore.reload({params: {start: 0, limit: pageS}});
	};
	
	function m_jobdet_add(){
		var edit_m_jobdet= new rapkdetListGrid.store.recordType({
			rapkdet_id: 0,
			jobdet_id: '',
			rapkdet_volume: 0,
			rapkdet_unit: '',
			rapkdet_price: 0
		});
		editor_m_jobdet.stopEditing();
		jobdetDataStore.insert(0, edit_m_jobdet);
		//rapkdetListGrid.getView().refresh();
		rapkdetListGrid.getSelectionModel().selectRow(0);
		editor_m_jobdet.startEditing(0);
	}
	
	function m_jobdet_confirm_delete(){
		// only one record is selected here
		if(rapkdetListGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod ini?', m_jobdet_delete);
		} else if(rapkdetListGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod-rekod ini?', m_jobdet_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Tidak ada data yang terpilih untuk diupdate',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	
	function m_jobdet_delete(btn){
		if(btn=='yes'){
			var rdata = null;
			var s = rapkdetListGrid.getSelectionModel().getSelections();
			for(var i = 0, r; r = s[i]; i++){
				rdata = r.data;
				jobdetDataStore.remove(r);
			}
			

			var detail_total = 0;
    		
    		var detail_store = rapkdetListGrid.getStore();
    		for(var i=0;i<detail_store.getCount();i++){
        		var vol = detail_store.getAt(i).data.rapkdet_volume;
        		var hrg = detail_store.getAt(i).data.rapkdet_price;
        		if(vol !== undefined && hrg !== undefined){
        			detail_total+= (detail_store.getAt(i).data.rapkdet_volume * detail_store.getAt(i).data.rapkdet_price);
        		}
    			
    		}
    		//rapk_jobdet_total_cfField.setValue(formatCurrency(detail_total));
    		total_rapkField.setValue(total_rapkField.getValue() - (rdata.rapkdet_volume * rdata.rapkdet_price));
    		rapk_jobdet_total_cfField.setValue(formatCurrency(total_rapkField.getValue()));
			total_rapk = total_rapkField.getValue();
		}  
	}

	function t_rapkdet_grouptemp_truncate(){
		Ext.Ajax.request({
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_t_rapk&m=t_rapkdet_grouptemp_truncate',
			success: function(response){
				var result=eval(response.responseText);
			},
			failure: function(response){
				Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
				});
			}
		});
	}
	t_rapkdet_grouptemp_truncate();

	function t_rapkdet_groupdettemp_truncate(){
	}
  	
  	/* END FUNCTION */

	/* START CONTROL PERMISSION */
	var pattr=new RegExp("R");
	var pattc=new RegExp("C");
	var pattu=new RegExp("U");
	var pattd=new RegExp("D");

	if(pattc.test(PERMISSION)==false){
		t_rapk_gbtn_add.setVisible(false);
	}else{
		t_rapk_gbtn_add.setVisible(true);
	}

	if(pattu.test(PERMISSION)==false){
		t_rapk_gbtn_update.setVisible(false);
	}else{
		t_rapk_gbtn_update.setVisible(true);
	}

	if(pattd.test(PERMISSION)==false){
		t_rapk_gbtn_delete.setVisible(false);
	}else{
		t_rapk_gbtn_delete.setVisible(true);
	}

	if(pattc.test(PERMISSION)==false && pattu.test(PERMISSION)==false){
		t_rapk_btn_Save.setVisible(false);
	}else{
		t_rapk_btn_Save.setVisible(true);
	}
	/* END CONTROL PERMISSION */
	
});
</script>
<body style: 'background: url(assets/images/desktop.jpg)'>
<div>
	<div class="col">
		<div id="elwindow_t_rapk_save"></div>
		<div>&nbsp;</div>
		<div id="fp_t_rapk"></div>
        <div id="elwindow_t_rapk_search"></div>
    </div>
</div>
</body>
</html>